package com.pipe.servicepipe.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pipe.commonutils.PageResult;
import com.pipe.commonutils.R;
import com.pipe.servicepipe.annotation.OperationAnnotation;
import com.pipe.servicepipe.entity.PipeSell;
import com.pipe.servicepipe.entity.vo.PipeSellQuery;
import com.pipe.servicepipe.service.PipeSellService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 销售表 前端控制器
 * </p>
 *
 * @author hetao
 * @since 2020-07-12
 */
@RestController
@RequestMapping("/pipe/sell")
@Api("销售管理")
public class PipeSellController {
    @Resource
    private PipeSellService pipeSellService;

    @OperationAnnotation("销售查询")
    @ApiOperation("销售分页查询")
    @PostMapping
    public R findSellByPage(
            @ApiParam(required = true, value = "查询条件")
            @RequestBody PipeSellQuery query
            ) throws Exception {
        Page page = new Page(query.getPageNum(),query.getPageSize());
        this.pipeSellService.findByPage(page,query);
        PageResult pageResult = new PageResult(page);
        return R.ok().message("查询成功").data("result",pageResult);
    }

    @OperationAnnotation("添加销售")
    @ApiOperation("添加销售")
    @PostMapping("/add")
    public R saveSell(@RequestBody PipeSell pipeSell) throws Exception {
        pipeSellService.savePell(pipeSell);
        return R.ok().message("添加成功");
    }

    @OperationAnnotation("删除销售信息")
    @ApiOperation("删除销售")
    @DeleteMapping
    public R deleteSell(@RequestParam("sid") String sid) throws Exception {
        pipeSellService.deleteById(sid);
        return R.ok().message("删除销售信息成功");
    }

    @OperationAnnotation("批量删除销售信息")
    @ApiOperation("批量删除销售")
    @DeleteMapping("batchDel")
    public R batchDel(@RequestParam("idsStr") String ids) throws Exception {
        this.pipeSellService.batchDel(ids);
        return R.ok().message("批量删除销售信息成功");
    }

}

